//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.ares.app.demo.common.mvc;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ares.app.demo.common.api.verify.ApiVerify;
import org.ares.app.demo.common.exception.a;
import org.ares.app.demo.common.mvc.filter.DemoRequestWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class DemoInterceptor extends HandlerInterceptorAdapter {
    @Resource
    ApiVerify multiIpVerify;
    @Resource
    ApiVerify namepassVerify;
    final ObjectMapper maper = new ObjectMapper();
    static final Logger log = LoggerFactory.getLogger(DemoInterceptor.class);

    public DemoInterceptor() {
    }

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        DemoRequestWrapper var4 = new DemoRequestWrapper(request);
        Object var5 = null;
        var5 = new HashMap();
        String var6 = var4.getRemoteAddr();
        ((Map)var5).put("client_request_ip", var6);
        log.info("request ip is:" + var6);
        if (!this.multiIpVerify.verify((Map)var5)) {
            throw new RuntimeException("request ip is invalid");
        } else {
            if (var4.getInputStream().available() != 0) {
                var5 = (Map)this.maper.readValue(var4.getInputStream(), Map.class);
                log.debug("preHandle: " + var5);
            }

            if (!this.namepassVerify.verify((Map)var5) && !this.namepassVerify.verify(request.getParameterMap())) {
                log.info("no parameter:UserName");
                throw new a();
            } else {
                log.debug("first verify is ok");
                return super.preHandle(request, response, handler);
            }
        }
    }
}
